const fs = require('fs')

function fsPromise() {
    let args = Array.from(arguments)
    let func = args.shift()
    return new Promise((resolve, reject) => {
        func(...args, function() {
            let args = Array.from(arguments)
            let err = args.shift()
            if (err) {
                reject(err)
            } else {
                resolve(...args)
            }
        })
    })
}

let exportObject = {
    constants: fs.constants,
}

const promiseMethodList = ['access', 'mkdir', 'lstat', 'readlink']
for (let method of promiseMethodList) {
    exportObject[method] = function() {
        return fsPromise(fs[method], ...arguments)
    }
}

module.exports = exportObject
